package com.hang.mapstruct;


import com.hang.entity.TbDocument;
import com.hang.model.dto.request.DocumentModelDTO;
import com.hang.model.vo.DocumentDetailVO;
import com.hang.model.vo.DocumentInfoVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

import java.util.LinkedList;
import java.util.List;

/**
 * @author lyh
 * @date 2022/1/14
 */

@Mapper(componentModel = "spring")
public interface DocumentMapStruct {
    TbDocument documentModelDTOToTbDocument(DocumentModelDTO documentModelDTO);

    default List<DocumentInfoVO> documentListToDocumentInfoVOList(List<TbDocument> documentList){
        List<DocumentInfoVO> documentInfoVOList = new LinkedList<>();
        documentList.forEach(
                document ->{
                    documentInfoVOList.add(documentToDocumentInfoVO(document));
                }
        );
        return documentInfoVOList;
    }

    @Mapping(source = "documentId",target = "documentId")
    @Mapping(source = "isComment",target = "isComment",qualifiedByName = "commentFormatter")
    DocumentInfoVO documentToDocumentInfoVO(TbDocument document);

    @Mapping(source = "documentId",target = "documentId")
    @Mapping(source = "isComment",target = "isComment",qualifiedByName = "commentFormatter")
    DocumentDetailVO documentToDocumentDetailVO(TbDocument dbDocument);

    @Named("commentFormatter")
    default String commentFormatter(Integer isComment){return isComment == 0?"否":"是";}
}
